package com.qing.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

import com.qing.service.SalaryService;
import com.qing.pojo.Salary;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qinghua
 * @since 2022-06-06
 */
@RestController
@RequestMapping("/salary")
public class SalaryController {
    @Autowired
    private SalaryService salaryService;

    @PostMapping("/insert")
    public Boolean save(@RequestBody Salary salary) {
        return salaryService.saveOrUpdate(salary);
    }

    @GetMapping("/deleteById/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return salaryService.removeById(id);
    }

    @GetMapping("/queryAll")
    public List<Salary> queryAll() {
        return salaryService.list();
    }

    @GetMapping("/queryById/{id}")
    public Salary findOne(@PathVariable Integer id) {
        return salaryService.getById(id);
    }

    @GetMapping("/queryAllAndName")
    public List<Map<String, Object>> queryAllAndName(){
        return salaryService.queryAllAndName();
    }

    @PostMapping("/queryAllAndNameByMonth")
    public List<Map<String, Object>> queryAllAndNameByMonth(@RequestBody String str){
        return salaryService.queryAllAndNameByMonth(JSONObject.parseObject(str).getString("yearMonth"));
    }

}

